package com.kujawnode.config.handler;

import com.kujawnode.constant.Constants;
import com.kujawnode.result.CodeEnum;
import com.kujawnode.result.R;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @version 1.0
 * @Author kujaw
 * @Date 2025/7/15 16:10
 * @注释
 */
@RestControllerAdvice //aop注解，拦截标注了@RestController的controller的所有方法
public class GlobalExceptionHandler {
    /**
     * 异常处理的方法(controller方法发生了异常，那么就使用该方法处理)
     */
    @ExceptionHandler(value = Exception.class)
    public R handleException(Exception e){
        e.printStackTrace();
        return R.FAIL(e.getMessage());
    }

    @ExceptionHandler(value = DataAccessException.class)
    public R handleDataAccessException(DataAccessException e){
        e.printStackTrace();
        return R.FAIL(e.getMessage());
    }

}
